<template>
	
	<view class="content">
	<view class="status_bar">
	         <!-- 这里是状态栏 -->
	     </view>
	 
		<view class="goods-list">
			<view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
				<view class="image-wrapper">
					<image :src="item.cover_image" mode="aspectFill"></image>
				</view>
				<view class="goods-title">
					<text class="goods-tag">{{item.activity_type_name}}</text>
					<text class="title clamp">{{item.name}}</text>
				</view>
				<view class="price-box">
					<text class="price">{{item.sales_price}}</text>
					<text>已售 {{item.total_sales}}</text>
				</view>
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>

	 

	</view>
</template>

<script>
	export default {

		data() {
			return {
				cateMaskState: 0, //分类面板展开状态
				headerPosition: "fixed",
				headerTop: "0px",
				loadingType: 'more', //加载更多状态
				filterIndex: 0, //排序 0 综合，1销量，2 价格
				cateId: 0, //已选三级分类id
				priceOrder: 0, //1 价格从低到高 2价格从高到低
				cateList: [],
				goodsList: [],
				searchtext:"",
				page: 1,
			};
		},

		onLoad(options) {
			// #ifdef H5
			this.headerTop = document.getElementsByTagName('uni-page-head')[0].offsetHeight + 'px';
			// #endif

		  
			this.getProductList();
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			if (e.scrollTop >= 0) {
				this.headerPosition = "fixed";
			} else {
				this.headerPosition = "absolute";
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.getProductList('refresh');
		},
		//加载更多
		onReachBottom() {
			this.getProductList();

		},
		methods: {
			onNavigationBarSearchInputConfirmed(e){
				this.searchtext = e.text;
				console.log(this.searchtext);
			    this.getProductList("refresh");
			},
		 
			getProductList(type = "add") {
				let param = {
					"keyword": this.searchtext,
					"page": 1,
					"pagesize": 10
				}
				if (type == "refresh") {
					param.page = 1;
					this.goodsList = [];
				}
			 
				let that = this;

				this.$util.req('/product/getlist', param, false, function(res) {

					that.goodsList = that.goodsList.concat(res.data);
					that.loadingType = res.data.length >= 10 ? 'more' : 'nomore';
					that.page += 1;
					console.log(res);
					if (type == "refresh") {
						uni.stopPullDownRefresh();
					}
				});

			},

		   
			//详情
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				let id = item.id;
			 
				let gourl = `/pages/product/product?id=`;
				if (item.activity_type == "pin") {
					gourl = `/pages/product/productpin?id=`;
				}

				uni.navigateTo({
					url: gourl + id
				})
			},
			stopPrevent() {}
		},
	}
</script>

<style lang="scss">
	  .status_bar {
	      height: var(--status-bar-height);
	      width: 100%;
	  }
	page,
	.content {
		background: $page-color-base;
	}

	.content {
		padding-top: 96upx;
	}

 
	/* 分类 */
	.cate-mask {
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 95;
		transition: .3s;

		.cate-content {
			width: 630upx;
			height: 100%;
			background: #fff;
			float: right;
			transform: translateX(100%);
			transition: .3s;
		}

		&.none {
			display: none;
		}

		&.show {
			background: rgba(0, 0, 0, .4);

			.cate-content {
				transform: translateX(0);
			}
		}
	}

	.cate-list {
		display: flex;
		flex-direction: column;
		height: 100%;

		.cate-item {
			display: flex;
			align-items: center;
			height: 90upx;
			padding-left: 30upx;
			font-size: 28upx;
			color: #555;
			position: relative;
		}

		.two {
			height: 64upx;
			color: #303133;
			font-size: 30upx;
			background: #f8f8f8;
		}

		.active {
			color: $base-color;
		}
	}

	/* 商品列表 */
	.goods-list {
		display: flex;
		flex-wrap: wrap;
		padding: 0 30upx;
		background: #fff;

		.goods-item {
			display: flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;

			&:nth-child(2n+1) {
				margin-right: 4%;
			}

			.goods-title {
				display: flex;
				height: 80upx;
				justify-content: flex-start;
				font-size: $font-lg;
				margin-top: 10rpx;
				.goods-tag {
					background-color: #ff0000;
					border-radius: 10rpx;
					color: #FFFFFF; 
					font-size: $font-sm;
					padding: 4rpx;
					margin-right: 4rpx;
					height: 40upx;	
				}

				.title {
					color: $font-color-dark;
				}

			}
		}

		.image-wrapper {
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}

		.price-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 10upx;
			font-size: 24upx;
			color: $font-color-light;
		}

		.price {
			font-size: $font-lg;
			color: $uni-color-primary;
			line-height: 1;

			&:before {
				content: '￥';
				font-size: 26upx;
			}
		}
	}
</style>

